package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.POJO.CheckItem;
import com.itheima.POJO.HealthScheme;
import org.apache.ibatis.annotations.*;

import java.util.Map;

public interface HealthSchemeMapper {

    //    新增
    @Insert("insert into t_healthscheme(code,title,keyword,scheme,content,remark,state) " +
            "values (#{code},#{title},#{keyword},#{scheme},#{content},#{remark},#{state})")
    public void addHealthScheme (HealthScheme healthScheme);


    //分页查询
    @Select("<script>select * from t_healthscheme " +
    "<where>" +
        "<if test=\"queryString2 != 'null'.toString()\"> " +
            "and (code like concat('%',#{queryString2},'%') or keyword like concat('%',#{queryString2},'%'))" +
        "</if>" +
        "<if test=\"queryScheme != 'null'.toString()\">  " +
            "and scheme = #{queryScheme}" +
        "</if> " +
    "</where> " +
    "</script>")
    Page<HealthScheme> findPage1(@Param("queryString2") String queryString2,@Param("queryScheme") String queryScheme);



    //删除
    @Delete("DELETE  FROM t_healthscheme WHERE id=#{id};")
    void delectHealthSchemeById(int id);

    //根据id查询
    @Select("SELECT * FROM t_healthscheme WHERE id =#{id}")
    HealthScheme findHealthSchemeById(Integer id);

          /*
       private Integer id;//主键
    private String code;//编码
    private String title;//标题
    private String keyword;//关键词
    private String scheme;//方案类别
    private String content;//内容
    private String remark;//备注
    private String state;//状态
    * */

    //新增
    @Update("<script>" +
            "update t_healthscheme\n" +
            "        <set>\n" +
            "            <if test=\"code != null\">\n" +
            "                code = #{code},\n" +
            "            </if>\n" +
            "            <if test=\"title != null\">\n" +
            "                title = #{title},\n" +
            "            </if>\n" +
            "            <if test=\"keyword != null\">\n" +
            "                keyword = #{keyword},\n" +
            "            </if>\n" +
            "            <if test=\"scheme != null\">\n" +
            "                scheme = #{scheme},\n" +
            "            </if>\n" +
            "            <if test=\"content != null\">\n" +
            "                content = #{content},\n" +
            "            </if>\n" +
            "            <if test=\"remark != null\">\n" +
            "                remark = #{remark},\n" +
            "            </if>\n" +
            "            <if test=\"state != null\">\n" +
            "                state = #{state},\n" +
            "            </if>\n" +
            "        </set>\n" +
            "        where id = #{id}" +
            "</script>")
    Long updateHealthScheme (HealthScheme healthScheme);

    //更改启用,禁用
//    @Update("update t_healthscheme set status = #{arg1} where id = #{arg0}")
    @Update("update t_healthscheme set state = #{state} where id = #{id}")
    public void updateHealthSchemeByStatus(@Param("id")Integer id,@Param("state")String state);


}
